<extend name="./public/frame.html"/>
<block name="content">
    <script type="text/javascript" charset="utf-8" src="/public/editor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="/public/editor/ueditor.all.min.js"> </script>
    <script type="text/javascript" charset="utf-8" src="/public/editor/lang/zh-cn/zh-cn.js"></script>

   <form class="layui-form" action="{:url('add')}" method="post">

       <input type="hidden" name="id" value="{$data.id}">

       <div class="layui-form-item">
            <label class="layui-form-label" style="width: 80px;">类型</label>
            <div class="layui-inline">
                <volist name="cate1" id="vo">
                    <if condition="$data.id gt 0">
                        <input type="radio" name="cate1_id" lay-filter="cate1" value="{$vo.id}" title="{$vo.name}" <if condition="$vo.id eq $data.cate1_id"> checked </if> />
                    <else/>
                        <input type="radio" name="cate1_id" lay-filter="cate1" value="{$vo.id}" title="{$vo.name}" <if condition="$vo.id eq 1"> checked </if> />
                    </if>
                </volist>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">类别</label>
            <div class="layui-input-block">
                <select name="cate2_id" id="cate2" lay-verify="required" lay-filter="cate2">
                    <option value="">请选择</option>
                    <if condition="$data.id gt 0">
                        <volist name="cate2_res" id="vo">
                            <option value="{$vo.id}" <if condition="$vo.id eq $data.cate2_id"> selected </if> >{$vo.name}</option>
                        </volist>
                    <else/>
                        <volist name="cate2" id="vo">
                            <option value="{$vo.id}">{$vo.name}</option>
                        </volist>
                    </if>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">子类别</label>
            <div class="layui-input-block">
                <select name="cate3_id" id="cate3" lay-verify="required" lay-filter="cate3">
                    <option value="">请选择</option>
                    <if condition="$data.id gt 0">
                        <volist name="cate3_res" id="vo">
                            <option value="{$vo.id}" <if condition="$vo.id eq $data.cate3_id"> selected </if> >{$vo.name}</option>
                        </volist>
                    <else/>
                        <volist name="cate3" id="vo">
                            <option value="{$vo.id}">{$vo.name}</option>
                        </volist>
                    </if>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">问题名称</label>
            <div class="layui-input-block">
                <input type="text" name="title" required lay-verify="required" placeholder="请输入标题" autocomplete="off"
                       class="layui-input" value="{$data.title}">
            </div>
        </div>

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">问题答案</label>
            <div class="layui-input-block">
                <!--<textarea name="content" placeholder="请输入答案" class="layui-textarea" lay-verify="required">{$data.content}</textarea>-->
                <script name="content" id="editor" type="text/plain" style="width:960px;height:300px;">{$data.content}</script></div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="submit">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>

    <script>
        layui.use('form', function () {
            var form = layui.form;
            form.on('radio(cate1)', function(data){
                var value = data.value;
                var url = "{:U('cateAjax')}";
                $.post(url,{cate_id:value},function(data){
                    var html = '<option value="">请选择</option>';
                    if(data.code==0){
                        var data = data.result;
                        $.each(data,function(key,val){
                            html += "<option value='"+val.id+"'>"+val.name+"</option>";
                            $("#cate2").empty();
                            $("#cate3").empty();
                            $("#cate2").append(html);
                            form.render('select');
                        })
                    }else{
                        $("#cate2").empty();
                        $("#cate2").append(html);
                        form.render('select');
                    }
                },'json');
            });

            form.on('select(cate2)', function(data){
                var value = data.value;
                var url = "{:U('cateAjax')}";
                $.post(url,{cate_id:value},function(data){
                    var html = '<option value="">请选择</option>';
                    if(data.code==0){
                        var data = data.result;
                        $.each(data,function(key,val){
                            html += "<option value='"+val.id+"'>"+val.name+"</option>";
                            $("#cate3").empty();
                            $("#cate3").append(html);
                            form.render('select');
                        })
                    }else{
                        $("#cate3").empty();
                        $("#cate3").append(html);
                        form.render('select');
                    }
                },'json');
            });
        });
    </script>

    <script type="text/javascript">
    var ue = UE.getEditor('editor',{
        zIndex : 0,// z轴
    });
    </script>
</block>
